package org.hzero.order.api.controller.v1;

import io.swagger.annotations.Api;
import org.hzero.core.util.Results;
import org.hzero.core.base.BaseController;
import org.hzero.mybatis.domian.Condition;
import org.hzero.order.app.service.SoLineService;
import org.hzero.order.config.SwaggerApiConfig;
import org.hzero.order.domain.entity.SoLine;
import org.hzero.order.domain.repository.SoLineRepository;
import org.hzero.order.domain.vo.SoLineVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.hzero.mybatis.helper.SecurityTokenHelper;

import io.choerodon.core.domain.Page;
import io.choerodon.core.iam.ResourceLevel;
import io.choerodon.mybatis.pagehelper.annotation.SortDefault;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import io.choerodon.mybatis.pagehelper.domain.Sort;
import io.choerodon.swagger.annotation.Permission;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;


/**
 * @ Description   :  销售订单行管理 API
 * @ Author        :  xiong.yilin@hand-china.com
 * @ CreateDate    :  2019/8/8 10:29
 */
@Api(tags = SwaggerApiConfig.SOLINE)
@RestController("soLineController.v1")
@RequestMapping("/v1/{organizationId}/so-lines")
public class SoLineController extends BaseController {

    @Autowired
    private SoLineRepository soLineRepository;

    @Autowired
    private SoLineService soLineService;


    @ApiOperation(value = "销售订单行明细")
    @Permission(level = ResourceLevel.ORGANIZATION)
    @GetMapping("/{orderNumber}")
    public ResponseEntity<List<SoLineVO>> detail
            (@PathVariable("organizationId") Long tenantId, @PathVariable("orderNumber") String orderNumber) {
        List<SoLineVO> soLineVOs = soLineService.selectSoLineByOrderNumber(orderNumber);
        return Results.success(soLineVOs);
    }


    @ApiOperation(value = "修改销售订单行")
    @Permission(level = ResourceLevel.ORGANIZATION)
    @PutMapping
    public ResponseEntity<SoLine> update(@PathVariable("organizationId") Long tenantId, @RequestBody SoLine soLine) {
        this.validObject(soLine);
        soLineService.updateLineById(soLine);
        return Results.success(soLine);
    }
}
